namespace IAM.Interface.Model
{
    using IAM.Interface.Common;
    using IAM.Interface.Model.ENUM;
    using IAM.Interface.Model.Interface;
    using System;
    using System.Text;

    public class Log : AbstractConvertObject, IConvertXml
    {
        private string _appaccount = "";
        private string _ipaddr = "";
        private string _note = "";
        private LogOperation _operation = LogOperation.LoginOK;
        private string _serialno = "";
        private DateTime _time = DateTime.Now;
        private LogType _type = LogType.Information;

        public override object ConvertToObject()
        {
            string operation;
            this.SerialNo = EnDeCoding.Decode(this.CurrentXmlNode.Attributes["SerialNo"].InnerText);
            this.Time = Convert.ToDateTime(this.CurrentXmlNode.Attributes["Time"].InnerText);
            string strType = this.CurrentXmlNode.Attributes["Type"].InnerText;
            switch (strType.ToLower())
            {
                case "information":
                    this.Type = LogType.Information;
                    goto Label_00BC;

                case "warning":
                    this.Type = LogType.Warning;
                    break;

                case "error":
                    this.Type = LogType.Error;
                    break;
            }
        Label_00BC:
            operation = this.CurrentXmlNode.Attributes["Operation"].InnerText;
            switch (operation.ToLower())
            {
                case "loginok":
                    this.Operation = LogOperation.LoginOK;
                    goto Label_0134;

                case "loginerror":
                    this.Operation = LogOperation.LoginError;
                    break;

                case "logout":
                    this.Operation = LogOperation.Logout;
                    break;
            }
        Label_0134:
            this.AppAccount = EnDeCoding.Decode(this.CurrentXmlNode.Attributes["AppAccount"].InnerText);
            this.IPAddr = EnDeCoding.Decode(this.CurrentXmlNode.Attributes["IPAddr"].InnerText);
            this.Note = EnDeCoding.Decode(this.CurrentXmlNode.Attributes["Note"].InnerText);
            return this;
        }

        public string AppAccount
        {
            get
            {
                return this._appaccount;
            }
            set
            {
                this._appaccount = value;
            }
        }

        public string IPAddr
        {
            get
            {
                return this._ipaddr;
            }
            set
            {
                this._ipaddr = value;
            }
        }

        public string Note
        {
            get
            {
                return this._note;
            }
            set
            {
                this._note = value;
            }
        }

        public LogOperation Operation
        {
            get
            {
                return this._operation;
            }
            set
            {
                this._operation = value;
            }
        }

        public string SerialNo
        {
            get
            {
                return this._serialno;
            }
            set
            {
                this._serialno = value;
            }
        }

        public DateTime Time
        {
            get
            {
                return this._time;
            }
            set
            {
                this._time = value;
            }
        }

        public LogType Type
        {
            get
            {
                return this._type;
            }
            set
            {
                this._type = value;
            }
        }

        public string XML
        {
            get
            {
                return (this.XMLBoday + this.XMLFinis);
            }
        }

        public string XMLBoday
        {
            get
            {
                StringBuilder _xml = new StringBuilder();
                _xml.Append(" <Log ");
                _xml.Append(" SerialNo=\"" + EnDeCoding.Encode(this.SerialNo.ToString()) + "\"");
                _xml.Append(" Time=\"" + this.Time.ToString() + "\"");
                _xml.Append(" Type=\"" + this.Type.ToString() + "\"");
                _xml.Append(" Operation=\"" + this.Operation.ToString() + "\"");
                _xml.Append(" AppAccount=\"" + EnDeCoding.Encode(this.AppAccount.ToString()) + "\"");
                _xml.Append(" IPAddr=\"" + EnDeCoding.Encode(this.IPAddr.ToString()) + "\"");
                _xml.Append(" Note=\"" + EnDeCoding.Encode(this.Note.ToString()) + "\"");
                _xml.Append(" />");
                return _xml.ToString();
            }
        }

        public string XMLFinis
        {
            get
            {
                return "";
            }
        }
    }
}

